package edu.zzuli.model.xt.jqqx.zzjggl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Controller;

import edu.zzuli.common.MyVisit;
import edu.zzuli.common.Pagination;
import edu.zzuli.model.core.JqGridBaseAction;
import edu.zzuli.model.orm.po.GG_CZYB;
import edu.zzuli.model.xt.jqqx.zzjggl.iface.ZzjgglService;

/**
 * @author tianshaojie
 * @date 2011-8-17
 * @discription : 机构人员列表
 */
@SuppressWarnings("serial")
@Controller
public class ListJgryAction extends JqGridBaseAction<GG_CZYB>{
	
	@Resource
	private ZzjgglService zzjgglService;
	
	private String ajaxResult;
	
	private int jgryCount;
	
	public String execute() {
		return this.refreshGridModel();
	}
	
	public List<GG_CZYB> listResults(Pagination pagination) {
		String jgbh = ServletActionContext.getRequest().getParameter("jgbh");
		if (jgbh == null || jgbh.length() == 0) {
			MyVisit myVisit = (MyVisit) ServletActionContext. getRequest().getSession().getAttribute("myVisit");
			jgbh = myVisit.getGG_JGBH().getJgbh();
		}
		String sql = "select id,mc,dlh from gg_czyb where jgbh = :JGBH and id != 'admin' order by gg_czyb.zcsj";
		MapSqlParameterSource paramMap = new MapSqlParameterSource();
		paramMap.addValue("JGBH", jgbh);
		return zzjgglService.selectSplit(sql,paramMap,pagination);
	}
	
	public String delete() {
		String ids = ServletActionContext.getRequest().getParameter("id");
		try {
			if (ids != null && !"".equals(ids)) {
				this.zzjgglService.deleteGG_CZYB(ids);
				this.ajaxResult = "success";
			} else {
				this.ajaxResult = "error";
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.ajaxResult = "error";
		}
		return this.ajaxResult;
	}

	public String execGetJgryCount() {
		String jgbh = ServletActionContext.getRequest().getParameter("jgbh");
		try {
			if (jgbh != null && !"".equals(jgbh)) {
				this.jgryCount = this.zzjgglService.getJgryCount(jgbh);
				this.ajaxResult = "success";
			} else {
				this.ajaxResult = "error";
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.ajaxResult = "error";
		}
		return this.ajaxResult;
	}
	
	public void setAjaxResult(String ajaxResult) {
		this.ajaxResult = ajaxResult;
	}

	public String getAjaxResult() {
		return ajaxResult;
	}

	public void setJgryCount(int jgryCount) {
		this.jgryCount = jgryCount;
	}

	public int getJgryCount() {
		return jgryCount;
	}
}
